package com.lixixi.tingshu.search.api;

import com.lixixi.tingshu.common.result.Result;
import com.lixixi.tingshu.model.search.AlbumInfoIndex;
import com.lixixi.tingshu.query.search.AlbumIndexQuery;
import com.lixixi.tingshu.search.service.SearchAlbumInfoService;
import com.lixixi.tingshu.vo.search.AlbumInfoIndexVo;
import com.lixixi.tingshu.vo.search.AlbumSearchResponseVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/search/albumInfo")
public class SearchApiAlbumInfoController {
	@Autowired
	SearchAlbumInfoService searchAlbumInfoService;

	@GetMapping("/{albumId}")
	Result<Map<String, Object>> searchAlbumInfo(@PathVariable("albumId") Long albumId){
		Map<String, Object> resultMap = searchAlbumInfoService.searchAlbumInfo(albumId);
		return Result.ok(resultMap);
	}

	@GetMapping("/upperAlbum/{albumId}")
	Result upperAlbum(@PathVariable("albumId") Long albumId) {
		searchAlbumInfoService.upperAlbum(albumId);
		return Result.ok();
	}

	@DeleteMapping("/lowerAlbum/{albumId}")
	Result lowerAlbum(@PathVariable("albumId") Long albumId) {
		searchAlbumInfoService.lowerAlbum(albumId);
		return Result.ok();
	}

	@GetMapping("/upperAlbumByBatch/{userId}")
	Result upperAlbumByBatch(@PathVariable("userId") Long userId) {
		searchAlbumInfoService.upperAlbumByBatch(userId);
		return Result.ok();
	}

	@PostMapping
	Result<AlbumSearchResponseVo> searchAlbumInfo(@RequestBody AlbumIndexQuery albumIndexQuery) {
		AlbumSearchResponseVo albumSearchResponseVo = searchAlbumInfoService.searchAlbumInfo(albumIndexQuery);
		return Result.ok(albumSearchResponseVo);
	}

	@GetMapping("/completeSuggest/{keyword}")
	Result<List<String>> completeSuggest(@PathVariable("keyword") String keyword) {
		List<String> completeSuggestList = searchAlbumInfoService.completeSuggest(keyword);
		return Result.ok(completeSuggestList);
	}

	@GetMapping("/channel/{category1Id}")
	Result<List<Map<String, Object>>> getChannel(@PathVariable("category1Id") Long category1Id) {
		List<Map<String, Object>> channelMap = searchAlbumInfoService.getChannel(category1Id);
		return Result.ok(channelMap);
	}

	// http://127.0.0.1/api/search/albumInfo/findRankingList/1/hotScore
	@GetMapping("/findRankingList/{category1Id}/{statType}")
	Result<List<AlbumInfoIndexVo>> findRankingList(@PathVariable("category1Id") Long category1Id, @PathVariable("statType") String statType){
		List<AlbumInfoIndexVo> albumInfoIndexVoList = searchAlbumInfoService.findRankingList(category1Id, statType);
		return Result.ok(albumInfoIndexVoList);
	}

	@GetMapping("/updateLatelyAlbumRanking")
	public Result updateLatelyAlbumRanking() {
		searchAlbumInfoService.updateLatelyAlbumRanking();
		return Result.ok();
	}

}
